package com.hllxd.hism.star.basic.service.service;

import com.hllxd.hism.star.basic.service.dao.mapper.mis.HdfsPathMapper;
import com.hllxd.hism.star.basic.service.model.TblDataHdfsPathManage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service("hdfsPathService")
public class HdfsPathServiceImpl implements HdfsPathService {

    @Autowired
    private HdfsPathMapper hdfsPathMapper;

    @Override
    public List<TblDataHdfsPathManage> listHdfsPath(Integer depth, String project) {
        TblDataHdfsPathManage param = new TblDataHdfsPathManage();
        param.depth = depth;
        if(StringUtils.isNotEmpty(project)) {
            param.project = project;
        }
        return hdfsPathMapper.selectHdfsPath(param);
    }

    @Override
    public Long setHdfsPath(TblDataHdfsPathManage aa) {
        long id;
        if (aa.getId() != null && aa.getId() > 0) {
            aa.setCreator(null);
            id = hdfsPathMapper.updateByPrimaryKeySelective(aa);
        } else {
            id = hdfsPathMapper.insertSelective(aa);
        }
        log.info("result code: {}", id);
        return id;
    }

    @Override
    public TblDataHdfsPathManage getHdfsPath(Long id) {
        return hdfsPathMapper.selectByPrimaryKey(id);
    }
}
